package com.service.impl;

import com.domain.Book;
import com.domain.BookAndComments;
import com.domain.Comments;
import com.entity.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mapper.BookAndCommentsMapper;
import com.service.BookAndCommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookAndCommentsServiceImpl implements BookAndCommentsService {

    @Autowired
    private BookAndCommentsMapper bookAndCommentsMapper;

    //显示所有评论
    @Override
    public List<BookAndComments> selectAll() {
        List<BookAndComments> list = bookAndCommentsMapper.selectAll();
        return list;
    }

    //插入中间表信息
    @Override
    public Integer addBookAndComments(BookAndComments bookAndComments) {
        return bookAndCommentsMapper.addBookAndComments(bookAndComments);
    }

    //插入评论表信息
    @Override
    public Integer addComments(Comments comments) {
        return bookAndCommentsMapper.addComments(comments);
    }

    @Override
    public PageResult findByIsbn(String isbn,int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<BookAndComments> page=bookAndCommentsMapper.findByIsbn(isbn);
        return new PageResult(page.getTotal(),page.getResult());
    }

    //搜索评论
    @Override
    public PageResult search(BookAndComments bookAndComments, int pageNum, int pageSize) {
        //分页查询
        PageHelper.startPage(pageNum,pageSize);
        //调用Dao
        Page<BookAndComments> page=bookAndCommentsMapper.search(bookAndComments);
        return new PageResult(page.getTotal(),page.getResult());
    }


}
